<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			#box{
				width: 800px;
				padding: 20px;
				text-align: center;
				border: 1px dotted #008000;
				margin: 50px auto;
			}
		</style>
	</head>
	<body>
		<div id="box"></div>
		<script>
			var obox = document.getElementById('box');
			setInterval(function(){
				startTimeSet(2018,1,1)
			},1000);
			function startTimeSet(y,m,d){
				//取当前的时间
				var nowDate = new Date();
				var NDs = nowDate.getTime();
				//设置将来的时间
				var futureDate = new Date(y,m-1,d);
				console.log(futureDate)
				var FTs = futureDate.getTime();
				
				var timerDiff = FTs-NDs;
				console.log( timerDiff)
				var diffDate = new Date(timerDiff);
				console.log(diffDate)
				//计算出相差天数  
			    var days=Math.floor(diffDate/(24*3600*1000))  
			  
			    //计算出小时数  
			  
			    var leave1=diffDate%(24*3600*1000)    //计算天数后剩余的毫秒数  
			    var hours=Math.floor(leave1/(3600*1000))  
			    //计算相差分钟数  
			    var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数  
			    var minutes=Math.floor(leave2/(60*1000))  
			    //计算相差秒数  
			    var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数  
			    var seconds=Math.round(leave3/1000)  
				
	            var html = "距离"+"<span style='color:red;'>过年</span>"+"还有"+days+"天"+hours+"小时"+minutes+"分"+seconds+"秒";
	            obox.innerHTML = html;
				
			}
			
			function to(num){
				 num>=10?num=num:num='0'+num;
				return num.toString();
			}
		</script>
	</body>
</html>
